package com.ukao.cashregister.pesenter;

import android.content.Context;

import com.ukao.cashregister.base.BasePresenter;
import com.ukao.cashregister.bean.RechargeBean;
import com.ukao.cashregister.bean.StringBean;
import com.ukao.cashregister.bean.VipTableBean;
import com.ukao.cashregister.consts.Constant;
import com.ukao.cashregister.consts.SaveParamets;
import com.ukao.cashregister.retrofit.ApiCallback;
import com.ukao.cashregister.view.VipTableView;

import java.util.HashMap;

/**
 * Created by ukaodev on 2017/6/26.
 */

public class VipTablePesenter extends BasePresenter<VipTableView> {

    public VipTablePesenter(VipTableView view) {
        attachView(view);
    }





    public void getViPTabData(Context mContext, int pageNum, int   pageSize, String  groupId,String cardId,String searchValue) {
        HashMap mHashMap = new HashMap<String, String>();
        mHashMap.put("pageNum",pageNum+"");
        mHashMap.put("pageSize",pageSize+"");
        mHashMap.put("groupId",groupId);
        mHashMap.put("cardId",cardId);
        mHashMap.put("accessToken", SaveParamets.getToken(mContext));
        mHashMap.put("searchValue",searchValue);


        addSubscription(apiStores.viplist(Constant.createParameter(mHashMap)),
                new ApiCallback<VipTableBean>() {
                    @Override
                    public void onSuccess(VipTableBean model) {
                        if (model.getHttpCode() == 200) {
                            VipTableBean   mData=model.getData();
                            mvpView.loadVipTableSucceed(mData.getList(),mData.getPages());
                        }else{
                            mvpView.loadFault(model.getMsg());
                        }

                    }


                    @Override
                    public void onFinish() {


                        ;
                    }
                });
    }

/*查询充值优惠列表*/
    public void queryRechargeList(Context mContext) {
        mvpView.showLoading();
        HashMap mHashMap = new HashMap<String, String>();
        mHashMap.put("accessToken", SaveParamets.getToken(mContext));
        addSubscription(apiStores.queryRechargeList(Constant.createParameter(mHashMap)),
                new ApiCallback<RechargeBean>() {
                    @Override
                    public void onSuccess(RechargeBean model) {
                        if (model.getHttpCode() == 200) {

                            mvpView.rechargeTableSucceed(model.getData());
                        }else{
                            mvpView.loadFault(model.getMsg());
                        }

                    }


                    @Override
                    public void onFinish() {
                    mvpView.hideLoading();


                    }
                });
    }

    /*查询充值优惠列表*/
    public void confirmRecharge(Context mContext,String userId,String amount  ) {
        mvpView.showLoading();
        HashMap mHashMap = new HashMap<String, String>();
        mHashMap.put("userId",userId);
        mHashMap.put("amount", amount);
        mHashMap.put("accessToken", SaveParamets.getToken(mContext));
        addSubscription(apiStores.confirmRecharge(Constant.createParameter(mHashMap)),
                new ApiCallback<StringBean>() {
                    @Override
                    public void onSuccess(StringBean model) {
                        if (model.getHttpCode() == 200) {

                            mvpView.rechargeSucceed(model.getMsg());
                        }else{
                            mvpView.loadFault(model.getMsg());
                        }

                    }


                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();


                    }
                });
    }
}
